# Input
# 100#101#1#5
# Output
# 1684340997

# Input
# 1#2#3
# Output
# invalid IP

def main():
    input_str = input().strip() # get input, eg. 100#101#1#5
    ip_sections = input_str.split("#") # split to 4 sections by '#'

    # check len, if len is not 4, invalid
    if len(ip_sections) != 4:
        print("invalid IP")
        return
    
    # check each section
    for section in ip_sections:
        if len(section) == 0 or not section.isdigit():  # section is empty or section is not digit, valid
            print("invalid IP")
            return
        if len(section) > 1 and section[0] == '0':  # section start with '0', valid
            print("invalid IP")
            return
        
    # check 1st section
    first_section = int(ip_sections[0])
    if first_section < 1 or first_section > 128:  # if 1st section not in 1~128, valid
        print("invalid IP")
        return
    
    # check rest 3 sections
    for i in range(1, 4):
        section_value = int(ip_sections[i])
        if section_value < 0 or section_value > 255:  # if not in 0~255, valid
            print("invalid IP")
            return

    # calculate the value finally
    ip_value = 0
    for i in range(4):
        ip_value = ip_value * 256 + int(ip_sections[i])  # move left 1 byte need to multi 256
    print(ip_value)  # print result


if __name__ == "__main__":
    main()